package com.hc.acoustics.util

import com.tencent.bugly.proguard.*
import kotlin.math.*

/**
 *
 */
object FormulaUtil {
    private const val param1 = 0.775
    fun cosMy(d: Double): Double {
        return cos(Math.PI / 180.0 * d)
    }

    fun tanMy(d: Double): Double {
        return tan(Math.PI / 180.0 * d)
    }

    fun sinMy(d: Double): Double {
        return sin(Math.PI / 180.0 * d)
    }

    /**
     * 根据温度 计算  声速
     */
    fun formula1_1(c: Double?): Double? = when (c == null) {
        true -> null
        else -> YcCalculator.roundOff(331.45 + 0.61 * c)
    }

    /**
     * 根据声速和频率 计算 波长
     */
    fun formula1_b(v: Double?, f: Double?): Double? = when (v == null || f == null) {
        true -> null
        else -> v / f
    }

    /**
     * 根频率 计算 周期
     */
    fun formula1_t(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 1000 / f
    }

    /**
     *根据声速和波长 计算 频率
     */
    fun formula1_f(v: Double?, λ: Double?): Double? = when (v == null || λ == null) {
        true -> null
        else -> v / λ
    }

    /**
     * 根据周期 计算 频率
     */
    fun formula1_f(t: Double?): Double? = when (t == null) {
        true -> null
        else -> 1000 / t
    }

    /**
     * 声学 - 声压级衰减(点声源)
     */
    fun formula2_2_1(a: Double?, x: Double?): Double? = when (a == null || x == null) {
        true -> null
        else -> a - 20.0 * log10(x)
    }

    /**
     * 声学 -已知频率求时间 求周期
     */
    fun formula2_3_1(f: Double?, a: Double): Double? = when (f == null) {
        true -> null
        else -> 1000 / f * a
    }

    /**
     * 声学 -已知频率求时间 求波长
     */
    fun formula2_3_2(f: Double?, a: Double): Double? = when (f == null) {
        true -> null
        else -> 340 / f * a
    }

    /**
     * 声压级叠加-随机相位
     */
    fun formula2_4_1(
        l1: Double?,
        l2: Double?,
        l3: Double?,
        l4: Double?,
        l5: Double?,
        l6: Double?,
        l7: Double?,
        l8: Double?
    ): Double? {
        if (l1 == null && l2 == null && l3 == null && l4 == null && l5 == null && l6 == null && l7 == null && l8 == null) {
            return null
        }
        val x = 10.0
        val y = 10.0
        return YcCalculator.roundOff(
            10 * log10(
                formula2_4_helper(l1, x, y) + formula2_4_helper(l2, x, y) + formula2_4_helper(
                    l3,
                    x,
                    y
                )
                        + formula2_4_helper(l4, x, y) + formula2_4_helper(
                    l5,
                    x,
                    y
                ) + formula2_4_helper(
                    l6,
                    x,
                    y
                ) + formula2_4_helper(l7, x, y)
                        + formula2_4_helper(l8, x, y)
            )
        )
    }

    /**
     * 声压级叠加-同相位
     */
    fun formula2_4_2(
        l1: Double?,
        l2: Double?,
        l3: Double?,
        l4: Double?,
        l5: Double?,
        l6: Double?,
        l7: Double?,
        l8: Double?
    ): Double? {
        if (l1 == null && l2 == null && l3 == null && l4 == null && l5 == null && l6 == null && l7 == null && l8 == null) {
            return null
        }
        val x = 10.0
        val y = 20.0
        return YcCalculator.roundOff(
            20 * log10(
                formula2_4_helper(l1, x, y) + formula2_4_helper(l2, x, y) + formula2_4_helper(
                    l3,
                    x,
                    y
                )
                        + formula2_4_helper(l4, x, y) + formula2_4_helper(
                    l5,
                    x,
                    y
                ) + formula2_4_helper(l6, x, y)
                        + formula2_4_helper(l7, x, y) + formula2_4_helper(l8, x, y)
            )
        )
    }

    /**
     * 声压级叠加-帮助
     */
    fun formula2_4_helper(l: Double?, x: Double, y: Double): Double = when (l) {
        null -> 0.0
        else -> x.pow(l / y)
    }


    /**
     * 声压级相减-随机相位
     */
    fun formula2_5_1(
        l0: Double?,
        l1: Double?,
        l2: Double?,
        l3: Double?,
        l4: Double?,
        l5: Double?,
        l6: Double?,
        l7: Double?,
        l8: Double?
    ): Double? {
        if (l0 == null && l1 == null && l2 == null && l3 == null && l4 == null && l5 == null && l6 == null && l7 == null && l8 == null) {
            return null
        }
        val x = 10.0
        val y = 10.0
        return YcCalculator.roundOff(
            10 * log10(
                formula2_5_helper(l0, x, y) - formula2_5_helper(l1, x, y) - formula2_5_helper(
                    l2,
                    x,
                    y
                )
                        - formula2_5_helper(l3, x, y) - formula2_5_helper(
                    l4,
                    x,
                    y
                ) - formula2_5_helper(l5, x, y)
                        - formula2_5_helper(l6, x, y) - formula2_5_helper(
                    l7,
                    x,
                    y
                ) - formula2_5_helper(l8, x, y)
            )
        )
    }

    /**
     * 声压级相减-同相位
     */
    fun formula2_5_2(
        l0: Double?,
        l1: Double?,
        l2: Double?,
        l3: Double?,
        l4: Double?,
        l5: Double?,
        l6: Double?,
        l7: Double?,
        l8: Double?
    ): Double? {
        if (l0 == null && l1 == null && l2 == null && l3 == null && l4 == null && l5 == null && l6 == null && l7 == null && l8 == null) {
            return null
        }
        val x = 10.0
        val y = 20.0
        return YcCalculator.roundOff(
            20 * log10(
                formula2_5_helper(l0, x, y) - formula2_5_helper(l1, x, y)
                        - formula2_5_helper(l2, x, y) - formula2_5_helper(
                    l3,
                    x,
                    y
                ) - formula2_5_helper(l4, x, y)
                        - formula2_5_helper(l5, x, y) - formula2_5_helper(
                    l6,
                    x,
                    y
                ) - formula2_5_helper(l7, x, y)
                        - formula2_5_helper(l8, x, y)
            )
        )
    }

    /**
     * 声压级相减-帮助
     */
    fun formula2_5_helper(l: Double?, x: Double, y: Double): Double = when (l) {
        null -> 0.0
        else -> x.pow(l / y)
    }

    /**
     * 声学 - 干涉频率与距离差 - 路程差
     */
    fun formula2_6_1(s1: Double?, s2: Double?): Double? {
        if (s1 == null || s2 == null) {
            return null
        } else {
            return abs(s1 - s2)
        }
    }

    /**
     * 声学 - 干涉频率与距离差 - 时间差
     */
    fun formula2_6_2(d: Double?, v: Double?): Double? {
        if (d == null || v == null) {
            return null
        } else {
            return 1000 * d / v
        }
    }

    /**
     * 声学 - 干涉频率与距离差 - 干涉频率1、2、3、4
     */
    fun formula2_6_3(v: Double?, d: Double?, x: Double): Double? {
        if (d == null || v == null) {
            return null
        } else {
            return x * v / d
        }
    }

    /**
     * 声学 - 干涉频率与距离差 - 距离差
     */
    fun formula2_6_4(v: Double?, f: Double?): Double? {
        if (f == null || v == null) {
            return null
        } else {
            return v / 2 / f
        }
    }

    /**
     * 声学 - 房间共振频率计算 - 距离差
     */
    fun formula2_7_1(x: Double?, y: Double?): Double? {
        if (x == null || y == null) {
            return null
        } else {
            return 340 / 2 / x * y
        }
    }

    /**
     * 电压转换-求电平值dBu
     */
    fun formula3_1_1(v: Double?): Double? = when (v) {
        null -> null
        else -> 20 * log10(v / param1)
    }

    /**
     * 电压转换-求电平值dBV
     */
    fun formula3_1_2(v: Double?): Double? = when (v) {
        null -> null
        else -> 20 * log10(v / 1)
    }

    /**
     * 电压转换-求电压值V
     */
    fun formula3_1_3(dBu: Double?): Double? = when (dBu) {
        null -> null
        else -> param1 * 10.0.pow(dBu / 20.0)
    }

    /**
     * 功放增益和放大倍数关系-求电压增益dB
     */
    fun formula3_2_1(x: Double?): Double? = when (x) {
        null -> null
        else -> 20 * log10(x)
    }

    /**
     * 功放增益和放大倍数关系-求电压倍数X
     */
    fun formula3_2_2(dB: Double?): Double? = when (dB) {
        null -> null
        else -> 10.0.pow(dB / 20.0)
    }

    /**
     * 已知功放输入、输出电压，求功放的放大倍数、增益 - 求电压倍数X
     */
    fun formula3_3_1(v1: Double?, v2: Double?): Double? = when (v1 == null || v2 == null) {
        true -> null
        else -> v2 * 1.0 / v1
    }

    /**
     * 已知功放输入、输出电压，求功放的放大倍数、增益 - 求电压增益dB
     */
    fun formula3_3_2(v1: Double?, v2: Double?): Double? = when (v1 == null || v2 == null) {
        true -> null
        else -> 20.0 * log10(v2 * 1.0 / v1)
    }

    /**
     * 已知功放输入、输出电压，求功放的放大倍数、增益 - 求电压放大倍数X
     */
    fun formula3_4_1(V: Double?, W: Double?, o: Int): Double? = when (V == null || W == null) {
        true -> null
        else -> sqrt(o * W) / V
    }

    /**
     * 已知功放输入、输出电压，求功放的放大倍数、增益 - 求电压增益dB
     */
    fun formula3_4_2(V: Double?, W: Double?, o: Int): Double? = when (V == null || W == null) {
        true -> null
        else -> 20.0 * log10(sqrt(o * W) / V)
    }

    /**
     * 电声dB的关系 - 求功率的增益dB
     */
    fun formula3_5_1(x: Double?): Double? = when (x == null) {
        true -> null
        else -> 10.0 * log10(x)
    }

    /**
     * 电声dB的关系 - 求电压增益dB
     */
    fun formula3_5_2(x: Double?): Double? = when (x == null) {
        true -> null
        else -> 20.0 * log10(x)
    }

    /**
     * 电声dB的关系 - 根据电压 求 dBu
     */
    fun formula3_5_31(V: Double?): Double? = when (V == null) {
        true -> null
        else -> 20.0 * log10(V / param1)
    }

    /**
     * 电声dB的关系 - 根据电压 求 dBV
     */
    fun formula3_5_32(V: Double?): Double? = when (V == null) {
        true -> null
        else -> 20.0 * log10(V)
    }

    /**
     * 电声dB的关系 - 根据电压、阻抗 求 dBm
     */
    fun formula3_5_33(V: Double?, R: Double?): Double? = when (V == null || R == null) {
        true -> null
        else -> 10.0 * log10(V * V * 1000 / R)
    }

    /**
     * 电声dB的关系 - 根据电压、阻抗 求 dBW
     */
    fun formula3_5_34(V: Double?, R: Double?): Double? = when (V == null || R == null) {
        true -> null
        else -> 10.0 * log10(V * V / R)
    }

    /**
     * 电声dB的关系 - 根据功率、阻抗 求 dBu
     */
    fun formula3_5_41(P: Double?, R: Double?): Double? = when (P == null || R == null) {
        true -> null
        else -> 20.0 * log10(sqrt(P * R) / param1)
    }

    /**
     * 电声dB的关系 - 根据功率、阻抗 求 dBv
     */
    fun formula3_5_42(P: Double?, R: Double?): Double? = when (P == null || R == null) {
        true -> null
        else -> 20.0 * log10(sqrt(P * R))
    }

    /**
     * 电声dB的关系 - 根据功率 求 dBm
     */
    fun formula3_5_43(P: Double?): Double? = when (P == null) {
        true -> null
        else -> 10.0 * log10(P * 1000)
    }

    /**
     * 电声dB的关系 - 根据功率 求 dBW
     */
    fun formula3_5_44(P: Double?): Double? = when (P == null) {
        true -> null
        else -> 10.0 * log10(P)
    }

    /**
     * 电声dB的关系 - 根据dBu 求 电压
     */
    fun formula3_5_51(a: Double?): Double? = when (a == null) {
        true -> null
        else -> param1 * 10.0.pow(a / 20.0)
    }

    /**
     * 电声dB的关系 - 根据阻抗 求 功率
     */
    fun formula3_5_52(a: Double?, R: Double?): Double? = when (R == null || a == null) {
        true -> null
        else -> (param1 * 10.0.pow(a / 20.0)).pow(2) / R
    }

    /**
     * 电声dB的关系 - 两个信号相同，幅度相同，相位不同叠加 根据相位差 求 混合后
     */
    fun formula3_6(a: Double?): Double? = when (a) {
        null -> null
        120.0 -> 0.0
        else -> 20.0 * log10(sqrt((1 + cosMy(a)).pow(2) + sinMy(a).pow(2)))
    }

    /**
     * 电声dB的关系 - 两个信号相同，幅度不同，相位不同叠加 根据幅度差和相位差 求 混合后
     */
    fun formula3_7(a: Double?, b: Double?): Double? = when (b == null || a == null) {
        true -> null
        else -> when (a == 0.0 && b == 120.0) {
            true -> 0.0
            else -> 20.0 * log10(sqrt((10.0.pow(a / 20.0) + cosMy(b)).pow(2) + sinMy(b).pow(2))) - a
        }
    }

    /**
     * 限幅器 - 限幅器（已知电压增益）- 求 放大倍数
     */
    fun formula4_1_1(a: Double?): Double? = when (a == null) {
        true -> null
        else -> 10.0.pow(a / 20.0)
    }

    /**
     * 限幅器 - 限幅器（已知电压增益）- 求 理论最大承受RMS电压
     */
    fun formula4_1_2(p: Double?, r: Double?): Double? = when (p == null || r == null) {
        true -> null
        else -> sqrt(p * r)
    }

    /**
     * 限幅器 - 限幅器（已知电压增益）- 求 限幅器阈值
     */
    fun formula4_1_3(b: Double?, u: Double?): Double? = when (b == null || u == null) {
        true -> null
        else -> 20 * log10(u / b / 0.775)
    }

    /**
     * 限幅器 - 限幅器（已知电压增益）- 求 ATT启动时间
     */
    fun formula4_1_4(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 2000 / f
    }

    /**
     * 限幅器 - 限幅器（已知电压增益）- 求 REL 释放时间
     */
    fun formula4_1_5(y: Double?): Double? = when (y == null) {
        true -> null
        else -> 10 * y
    }

    /**
     * 限幅器 - 限幅器（已知放大倍数）- 求 电压增益
     */
    fun formula4_2_1(b: Double?): Double? = when (b == null) {
        true -> null
        else -> 20.0 * log10(b)
    }

    /**
     * 限幅器 - 限幅器（已知放大倍数）- 求 理论最大承受RMS电压
     */
    fun formula4_2_2(p: Double?, r: Double?): Double? = when (p == null || r == null) {
        true -> null
        else -> sqrt(p * r)
    }

    /**
     * 限幅器 - 限幅器（已知放大倍数）- 求 限幅器阈值
     */
    fun formula4_2_3(b: Double?, u: Double?): Double? = when (b == null || u == null) {
        true -> null
        else -> 20 * log10(u / b / 0.775)
    }

    /**
     * 限幅器 - 限幅器（已知放大倍数）- 求 ATT启动时间
     */
    fun formula4_2_4(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 2000 / f
    }

    /**
     * 限幅器 - 限幅器（已知放大倍数）- 求 REL 释放时间
     */
    fun formula4_2_5(y: Double?): Double? = when (y == null) {
        true -> null
        else -> 10 * y
    }

    /**
     * 限幅器 - 限幅器（使用万用表）- 求 放大倍数
     */
    fun formula4_3_1(v1: Double?, v2: Double?): Double? = when (v1 == null || v2 == null) {
        true -> null
        else -> v2 / v1
    }

    /**
     * 限幅器 - 限幅器（使用万用表）- 求 理论最大承受RMS电压
     */
    fun formula4_3_2(p: Double?, r: Double?): Double? = when (p == null || r == null) {
        true -> null
        else -> sqrt(p * r)
    }

    /**
     * 限幅器 - 限幅器（使用万用表）- 求 限幅器阈值
     */
    fun formula4_3_3(b: Double?, u: Double?): Double? = when (b == null || u == null) {
        true -> null
        else -> 20 * log10(u / b / 0.775)
    }

    /**
     * 限幅器 - 限幅器（使用万用表）- 求 ATT启动时间
     */
    fun formula4_3_4(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 2000 / f
    }

    /**
     * 限幅器 - 限幅器（使用万用表）- 求 REL 释放时间
     */
    fun formula4_3_5(y: Double?): Double? = when (y == null) {
        true -> null
        else -> 10 * y
    }

    /**
     * 限幅器 - 限幅器（已知功放灵敏度）- 求 放大倍数
     */
    fun formula4_4_1(p1: Double?, r1: Double?, v1: Double?): Double? =
        when (p1 == null || r1 == null || v1 == null) {
            true -> null
            else -> sqrt(p1 * r1) / v1
        }

    /**
     * 限幅器 - 限幅器（已知功放灵敏度）- 求 理论最大承受RMS电压
     */
    fun formula4_4_2(p: Double?, r: Double?): Double? = when (p == null || r == null) {
        true -> null
        else -> sqrt(p * r)
    }

    /**
     * 限幅器 - 限幅器（已知功放灵敏度）- 求 限幅器阈值
     */
    fun formula4_4_3(b: Double?, u: Double?): Double? = when (b == null || u == null) {
        true -> null
        else -> 20 * log10(u / b / 0.775)
    }

    /**
     * 限幅器 - 限幅器（已知功放灵敏度）- 求 ATT启动时间
     */
    fun formula4_4_4(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 2000 / f
    }

    /**
     * 限幅器 - 限幅器（已知功放灵敏度）- 求 REL 释放时间
     */
    fun formula4_4_5(y: Double?): Double? = when (y == null) {
        true -> null
        else -> 10 * y
    }

    /**
     * 超低音阵列 - 超低音心形指向简单计算①
     */
    fun formula5_1_1(w: Double?, d: Double?): Double? = when (w == null || d == null) {
        true -> null
        else -> (w + d) * 1000.0 / 340
    }

    /**
     * 超低音阵列 - 超低音心形指向简单计算①
     */
    fun formula5_1_2(t: Double?): Double? = when (t == null) {
        true -> null
        else -> 250 / t
    }

    /**
     * 超低音阵列 - 超低音心形指向的简单计算②    求两个超低音箱之间距离
     */
    fun formula5_2_1(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 340 / 4 / f
    }

    /**
     * 超低音阵列 - 超低音心形指向的简单计算②    求给音箱A加延时
     */
    fun formula5_2_2(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 250 / f
    }

    /**
     * 系统设计 - 线阵列近场距离  求声速
     */
    fun formula6_1_1(t: Double?): Double? = when (t == null) {
        true -> null
        else -> 331.45 + 0.61 * t
    }

    /**
     * 系统设计 - 线阵列近场距离  求近场距离
     */
    fun formula6_1_2(l: Double?, f: Double?, v: Double?): Double? =
        when (l == null || f == null || v == null) {
            true -> null
            else -> l * l * f / 2.0 / v
        }

    /**
     * 系统设计 - 带宽到Q值的转换  求带宽Bandwidth
     */
    fun formula6_2_1(q: Double?): Double? {
        if (q == null) {
            return null
        } else {
            val a = (2 * q * q + 1) / 2 / q / q
            val b = (2 * q * q + 1) / q / q
            val c = sqrt(b * b / 4 - 1)
            return log10(a + c) / 0.301
        }
    }

    /**
     * 系统设计 - 带宽到Q值的转换 求Q值
     */
    fun formula6_2_2(x: Double?): Double? = when (x == null) {
        true -> null
        else -> sqrt(2.0.pow(x)) / (2.0.pow(x) - 1)
    }

    /**
     * 系统设计 - 带宽到Q值的转换 求低端频率
     */
    fun formula6_2_3(f1: Double?, f2: Double?): Double? = when (f1 == null || f2 == null) {
        true -> null
        else -> f1 * f1 / f2
    }

    /**
     * 系统设计 - 带宽到Q值的转换 根据高端频率和低端频率求 带宽Bandwidth
     */
    fun formula6_2_4(f2: Double?, f3: Double?): Double? = when (f2 == null || f3 == null) {
        true -> null
        else -> log10(f2 / f3 / 0.301)
    }

    /**
     * 系统设计 - 带宽到Q值的转换 根据中心频率、高端频率和低端频率求 带Q值
     */
    fun formula6_2_5(f1: Double?, f2: Double?, f3: Double?): Double? =
        when (f1 == null || f2 == null || f3 == null) {
            true -> null
            else -> f1 / (f2 - f3)
        }

    /**
     * 系统设计 - 补声音箱延时的计算
     */
    fun formula6_3(x: Double?, c: Double?): Double? = when (x == null || c == null) {
        true -> null
        else -> x / (331.45 + 0.6 * c) * 1000
    }

    /**
     * 系统设计 - 波瓣数量计算
     */
    fun formula6_4(f: Double?, l: Double?, v: Double?): Double? =
        when (f == null || l == null || v == null) {
            true -> null
            else -> YcCalculator.roundOff(2 * f * l / v, 0) * 2
        }

    /**
     * 系统设计 - 天花喇叭覆盖范围计算 求 覆盖半径
     */
    fun formula6_5_1(h1: Double?, h2: Double?, d: Double?): Double? =
        when (h1 == null || h2 == null || d == null) {
            true -> null
            else -> (h1 - h2) * tanMy(d / 2)
        }

    /**
     * 系统设计 - 天花喇叭覆盖范围计算 求 扬声器数量<估算>
     */
    fun formula6_5_2(s: Double?, r: Double?, type: Int): Double? =
        when (s == null || r == null) {
            true -> null
            else -> when (type) {
                1 -> s / 4 / r / r
                2 -> ((sqrt(s) - 2 * r) / sqrt(2.0) / r + 1).pow(2)
                3 -> ((sqrt(s) - 2 * r) / r + 1).pow(2)
                else -> null
            }
        }

    /**
     * 系统设计 - 天花喇叭覆盖范围计算 求 天花喇叭布置间距
     */
    fun formula6_5_3(r: Double?, type: Int): Double? = when (r == null) {
        true -> null
        else -> when (type) {
            1 -> 2 * r
            2 -> sqrt(2.0) * r
            3 -> r
            else -> null
        }
    }

    /**
     * 系统设计 - 天花喇叭覆盖范围计算 求 扬声器额定声压级
     */
    fun formula6_5_4(l: Double?, h1: Double?, h2: Double?): Double? =
        when (l == null || h1 == null || h2 == null) {
            true -> null
            else -> l + 20 * log10(h1 - h2)
        }

    /**
     * 系统设计 - 分频上限 求 单元距离上限
     */
    fun formula6_6_1(f: Double?, x: Double): Double? = when (f == null) {
        true -> null
        else -> 344 / f / x
    }

    /**
     * 系统设计 - 分频上限 求 频率上限
     */
    fun formula6_6_2(d: Double?, x: Double): Double? = when (d == null) {
        true -> null
        else -> 344 / d / x
    }

    /**
     * 系统设计 - 分频上限 求 波长
     */
    fun formula6_6_3(f: Double?): Double? = when (f == null) {
        true -> null
        else -> 344 / f
    }

    /**
     * 系统设计 - 分频上限 求 距离/波长
     */
    fun formula6_6_4(d: Double?, b: Double?): Double? = when (d == null || b == null) {
        true -> null
        else -> d / b
    }


    /**
     * 声学增益 - 最大物理距离（MPD）
     */
    fun formula7_1(a: Double?, b: Double?, c: Double?): Double? =
        when (a == null || b == null || c == null) {
            true -> null
            else -> 10.0.pow((c - a - b) / 20)
        }

    /**
     * 声学增益 - 单个话筒所需声学增益（NAG）
     */
    fun formula7_2(a: Double?, b: Double?, c: Double?): Double? =
        when (a == null || b == null || c == null) {
            true -> null
            else -> 20 * log10(c / a) - 20 * log10(b / a)
        }

    /**
     * 声学增益 - 开启话筒数量NOM 求 相应的增益衰减量 dB
     */
    fun formula7_3_1(a: Double?): Double? = when (a == null) {
        true -> null
        else -> 10 * log10(a)
    }

    /**
     * 声学增益 - 开启话筒数量NOM 求 多个话筒所需声学增益 dB
     */
    fun formula7_3_2(c: Double?, d: Double?, x: Int): Double? = when (c == null || d == null) {
        true -> null
        else -> c + d + x
    }

    /**
     * 声学增益 - 潜在声学增益PAG
     */
    fun formula7_4(a: Double?, b: Double?, c: Double?, d: Double?): Double? =
        when (a == null || b == null || c == null || d == null) {
            true -> null
            else -> 20 * log10(a) + 20 * log10(b) - 20 * log10(c) - 20 * log10(d)
        }

    /**
     * 声学增益 - 最大开启话筒数量
     */
    fun formula7_5_1(a: Double?, b: Double?, c: Double?, d: Double?): Double? =
        when (a == null || b == null || c == null || d == null) {
            true -> null
            else -> (b * a) * (b * a) / (d * 2 * c) / (d * 2 * c)
        }

    /**
     * 声学增益 - 最大扬声器到最远听音人的距离
     */
    fun formula7_5_2(a: Double?, b: Double?, c: Double?, e: Double?): Double? =
        when (a == null || b == null || c == null || e == null) {
            true -> null
            else -> b * a / 2 / c / sqrt(e)
        }

    /**
     * 声学增益 - 最大讲话者到话筒的距离
     */
    fun formula7_5_3(a: Double?, b: Double?, d: Double?, e: Double?): Double? =
        when (a == null || b == null || d == null || e == null) {
            true -> null
            else -> b * a / 2 / d / sqrt(e)
        }

    /**
     * 声学增益 - 最小话筒到扬声器的距离
     */
    fun formula7_5_4(a: Double?, c: Double?, d: Double?, e: Double?): Double? =
        when (a == null || c == null || d == null || e == null) {
            true -> null
            else -> 2 * c * d * sqrt(e) / a
        }

    /**
     * 声学增益 - 最小等效声学距离EAD
     */
    fun formula7_5_5(b: Double?, c: Double?, d: Double?, e: Double?): Double? =
        when (b == null || c == null || d == null || e == null) {
            true -> null
            else -> 2 * c * d * sqrt(e) / b
        }
}